package com.kmust.dream.wanderingdream.donation.controller;

import java.util.Arrays;
import java.util.Map;

import com.kmust.dream.wanderingdream.donation.feign.UploadAdvice;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.kmust.dream.wanderingdream.donation.entity.FeedbackInformationEntity;
import com.kmust.dream.wanderingdream.donation.service.FeedbackInformationService;
import com.kmust.dream.wanderingdream.comm.utils.PageUtils;
import com.kmust.dream.wanderingdream.comm.utils.R;
import org.springframework.web.multipart.MultipartFile;


/**
 * 
 *
 * @author Leng
 * @email Leng81605@gmail.com
 * @date 2021-07-12 21:35:52
 */
@RestController
@Api(tags = "受捐赠者回馈信息")
@RequestMapping("donation/feedbackinformation")
public class FeedbackInformationController {
    @Autowired
    private FeedbackInformationService feedbackInformationService;
    @Autowired
    private UploadAdvice uploadAdvice;

    /**
     * 列表
     */
    @GetMapping("/list")

    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = feedbackInformationService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @GetMapping("/info/{fbId}")

    public R info(@PathVariable("fbId") Integer fbId){
		FeedbackInformationEntity feedbackInformation = feedbackInformationService.getById(fbId);

        return R.ok().put("feedbackInformation", feedbackInformation);
    }

    /**
     * 保存
     */
    @PostMapping("/save")

    public R save(FeedbackInformationEntity feedbackInformation, @RequestParam("file") MultipartFile multipartFile){
        if (multipartFile.isEmpty()){
            feedbackInformation.setUsingImg(null);
        }
        else{
            String url = uploadAdvice.getUrl(multipartFile);
            feedbackInformation.setUsingImg(url);
        }
        System.out.println(feedbackInformation);
		feedbackInformationService.save(feedbackInformation);
        return R.ok();
    }

    /**
     * 修改
     */
    @PutMapping("/update")

    public R update(@RequestBody FeedbackInformationEntity feedbackInformation){
		feedbackInformationService.updateById(feedbackInformation);

        return R.ok();
    }

    /**
     * 删除
     */
    @DeleteMapping("/delete")

    public R delete(@RequestBody Integer[] fbIds){
		feedbackInformationService.removeByIds(Arrays.asList(fbIds));

        return R.ok();
    }

}
